package org.afun.oldhand.order.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

import org.afun.oldhand.R;
import org.afun.oldhand.base.BaseFragment;
import org.afun.oldhand.order.adapter.OrderItemAdapter;
import org.afun.oldhand.order.javaBean.ItemBean;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link OrderFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class OrderFragment extends BaseFragment implements View.OnClickListener  {
    private View view;
    private Button order_all;
    private Button order_unuse;
    private Button order_unevaluate;
    private Button order_backafter;
    private Order0Fragment order0Fragment;
    private Order1Fragment order1Fragment;
    private Order2Fragment order2Fragment;
    private Order3Fragment order3Fragment;
    public OrderFragment() {
        // Required empty public constructor
    }

    public static OrderFragment newInstance() {
        OrderFragment fragment = new OrderFragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return initView();
    }

    @Override
    public View initView() {
        if (view == null) {
            view = View.inflate(mContext, R.layout.fragment_order, null);
        }
//        Log.e("test", "initView--order...");
        order0Fragment=new Order0Fragment();
        order1Fragment=new Order1Fragment();
        order2Fragment=new Order2Fragment();
        order3Fragment=new Order3Fragment();
        replaceFragment(order0Fragment);

        order_all=view.findViewById(R.id.order_all);
        order_all.setOnClickListener(this);

        order_unuse=view.findViewById(R.id.order_unuse);
        order_unuse.setOnClickListener(this);

        order_unevaluate=view.findViewById(R.id.order_unevaluate);
        order_unevaluate.setOnClickListener(this);

        order_backafter=view.findViewById(R.id.order_backafter);
        order_backafter.setOnClickListener(this);

        return view;
    }

    // 动态切换fragment
    private void replaceFragment(Fragment fragment) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction transation = fragmentManager.beginTransaction();
        transation.replace(R.id.orderFrameLayout, fragment);
        transation.commit();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.order_all:
                replaceFragment(order0Fragment);
//                Toast.makeText(mContext,"全部",Toast.LENGTH_SHORT).show();
                break;
            case R.id.order_unuse:
                replaceFragment(order1Fragment);
//                Toast.makeText(mContext,"待使用",Toast.LENGTH_SHORT).show();
                break;
            case R.id.order_unevaluate:
                replaceFragment(order2Fragment);
                break;

            case R.id.order_backafter:
                replaceFragment(order3Fragment);
                break;

            default:
                break;
        }
    }
}